<?php
class mysql 
{
	private $mysql;
	
	public function __construct()
	{
		@$this->mysql = mysql_connect(HOST, USER, PASS) or die('数据库连接失败！请检查conf/web.conf.php原因：' . mysql_error());
		@mysql_select_db(DB_NAME, $this->mysql) or die('数据库选择失败！原因：'. mysql_error());
		mysql_query("set names '" . CHARSET . "'");
	}
	
	//查询单挑
	public function _select($sql)
	{
		$res = mysql_query($sql);
		if($row = mysql_fetch_assoc($res))
		{
			return $row;
		}
	}
	//查询多条
	public function _selects($sql)
	{
		$results = array();
		if($res = mysql_query($sql))
		{
			while($row = mysql_fetch_assoc($res))
			{
				$results[] = $row;
			}
		}
		return $results;
	}
	//插入单挑
	public function _insert($sql)
	{
		if(mysql_query($sql))
		{
			if($num = mysql_insert_id())
			{
				return $num;
			}
			else
			{
				return false;
			}
		}
	}
	//更新表
	public function _update($sql)
	{
		if(mysql_query($sql))
		{
			if($num = mysql_affected_rows())
			{
				return $num;			//返回影响的次数
			}
		}
	}
	//删除数据
	public function _delete($sql)
	{
		if(mysql_query($sql))
		{
			if($num = mysql_affected_rows())
			{
				return $num;			//返回影响的次数
			}
		}
	}
	
   /**
	*函数: msg($postList)
	*功能: 通用信息提示
	*参数:
	*返回: 
	*/
	public function msg($url, $show)
	{
		$msg = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="refresh" content="2; url=' . $url . '" />
<title>信息提示--' . $show . '</title>
</head>
<style>
*{
	margin:0;
	padding:0;
	font-size:13px;
}
body{
	background-color:#FFFFFF;
}
div{
	margin:100px auto auto auto;
	background:url(style/image/msg_bg.png) no-repeat 0 0;
	width:612px;
	height:312px;
	text-align:center;
	color:#FF6600;
	padding-top:110px;
}
div a{
	color:green;
	text-decoration:none;
}

div a:hover{
	color:red;
	text-decoration:underline;
}
</style>
<body>
<div>
' . $show . '<br /><br />
<a href="' . $url . '">如果页面无法跳转，请点这里</a>
</div>

</body>
</html>';
		echo $msg;
		exit();
	}
}
?>